<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>🎲 魏女神的课堂点名神器 🎲</title>
    <style>
        * {
            margin: 0;
            padding: 0;
            box-sizing: border-box;
        }

        body {
            font-family: 'Microsoft YaHei', 'SimHei', sans-serif;
            background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
            min-height: 100vh;
            display: flex;
            justify-content: center;
            align-items: center;
            overflow-x: hidden;
            overflow-y: auto;
            position: relative;
            padding: 20px 0;
        }

        /* 可爱的背景装饰 */
        .decoration {
            position: absolute;
            font-size: 3rem;
            opacity: 0.15;
            animation: float 6s ease-in-out infinite;
        }

        @keyframes float {
            0%, 100% { transform: translateY(0px) rotate(0deg); }
            50% { transform: translateY(-20px) rotate(10deg); }
        }

        .container {
            background: rgba(255, 255, 255, 0.95);
            border-radius: 30px;
            padding: 30px 40px;
            box-shadow: 0 20px 60px rgba(0, 0, 0, 0.3);
            text-align: center;
            max-width: 900px;
            width: 90%;
            position: relative;
            z-index: 10;
            margin: auto;
        }

        h1 {
            color: #667eea;
            font-size: 2.2rem;
            margin-bottom: 10px;
            text-shadow: 2px 2px 4px rgba(0, 0, 0, 0.1);
        }

        .subtitle {
            color: #764ba2;
            font-size: 1.1rem;
            margin-bottom: 20px;
            font-weight: bold;
        }

        .name-display {
            background: linear-gradient(135deg, #ffecd2 0%, #fcb69f 100%);
            border-radius: 20px;
            padding: 80px 40px;
            margin: 25px 0;
            box-shadow: inset 0 4px 10px rgba(0, 0, 0, 0.1);
            position: relative;
            overflow: hidden;
        }

        .name-display::before {
            content: '🎯';
            position: absolute;
            top: 10px;
            right: 10px;
            font-size: 3rem;
            opacity: 0.3;
        }

        #currentName {
            font-size: 6rem;
            font-weight: bold;
            color: #d63031;
            text-shadow: 3px 3px 6px rgba(0, 0, 0, 0.2);
            transition: all 0.3s ease;
            min-height: 120px;
            display: flex;
            align-items: center;
            justify-content: center;
        }

        #currentName.winner {
            animation: celebration 0.6s ease-in-out;
            font-size: 8rem;
            color: #fd79a8;
        }

        @keyframes celebration {
            0%, 100% { transform: scale(1) rotate(0deg); }
            25% { transform: scale(1.2) rotate(-5deg); }
            75% { transform: scale(1.2) rotate(5deg); }
        }

        .controls {
            margin: 20px 0;
        }

        #startBtn {
            background: linear-gradient(135deg, #f093fb 0%, #f5576c 100%);
            color: white;
            border: none;
            padding: 22px 55px;
            font-size: 1.6rem;
            font-weight: bold;
            border-radius: 50px;
            cursor: pointer;
            box-shadow: 0 10px 30px rgba(245, 87, 108, 0.4);
            transition: all 0.3s ease;
            position: relative;
            overflow: hidden;
        }

        #startBtn:hover {
            transform: translateY(-3px);
            box-shadow: 0 15px 40px rgba(245, 87, 108, 0.6);
        }

        #startBtn:active {
            transform: translateY(0);
        }

        #startBtn.running {
            background: linear-gradient(135deg, #fa709a 0%, #fee140 100%);
            animation: pulse 1s ease-in-out infinite;
        }

        @keyframes pulse {
            0%, 100% { transform: scale(1); }
            50% { transform: scale(1.05); }
        }

        .speed-control {
            margin: 25px 0;
            padding: 20px;
            background: rgba(102, 126, 234, 0.1);
            border-radius: 15px;
        }

        .speed-label {
            font-size: 1.2rem;
            color: #667eea;
            font-weight: bold;
            margin-bottom: 12px;
            display: flex;
            align-items: center;
            justify-content: center;
            gap: 10px;
        }

        #speedSlider {
            width: 80%;
            height: 15px;
            border-radius: 10px;
            outline: none;
            -webkit-appearance: none;
            appearance: none;
            background: linear-gradient(to right, #a8edea 0%, #fed6e3 100%);
            cursor: pointer;
        }

        #speedSlider::-webkit-slider-thumb {
            -webkit-appearance: none;
            width: 30px;
            height: 30px;
            border-radius: 50%;
            background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
            cursor: pointer;
            box-shadow: 0 4px 10px rgba(0, 0, 0, 0.3);
        }

        #speedSlider::-moz-range-thumb {
            width: 30px;
            height: 30px;
            border-radius: 50%;
            background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
            cursor: pointer;
            border: none;
            box-shadow: 0 4px 10px rgba(0, 0, 0, 0.3);
        }

        .speed-value {
            margin-top: 12px;
            font-size: 1.1rem;
            color: #764ba2;
            font-weight: bold;
        }

        .emoji-rain {
            position: fixed;
            font-size: 2rem;
            animation: fall 3s linear;
            pointer-events: none;
            z-index: 1000;
        }

        @keyframes fall {
            to {
                transform: translateY(100vh) rotate(360deg);
                opacity: 0;
            }
        }

        .fun-facts {
            margin-top: 20px;
            padding: 15px;
            background: rgba(253, 121, 168, 0.1);
            border-radius: 15px;
            font-size: 1rem;
            color: #d63031;
            font-style: italic;
        }

        .student-list {
            margin-top: 20px;
            padding: 15px;
            background: rgba(102, 126, 234, 0.1);
            border-radius: 15px;
        }

        .student-list-header {
            display: flex;
            align-items: center;
            justify-content: center;
            gap: 10px;
            cursor: pointer;
            user-select: none;
            padding: 10px;
            border-radius: 10px;
            transition: background 0.3s ease;
        }

        .student-list-header:hover {
            background: rgba(102, 126, 234, 0.15);
        }

        .student-list h3 {
            color: #667eea;
            margin: 0;
            font-size: 1.3rem;
        }

        .toggle-icon {
            font-size: 1.5rem;
            transition: transform 0.3s ease;
        }

        .toggle-icon.expanded {
            transform: rotate(180deg);
        }

        .student-chips {
            display: none;
            flex-wrap: wrap;
            gap: 8px;
            justify-content: center;
            margin-top: 15px;
            max-height: 300px;
            overflow-y: auto;
            padding: 10px;
        }

        .student-chips.show {
            display: flex;
        }

        .student-chip {
            background: linear-gradient(135deg, #a8edea 0%, #fed6e3 100%);
            padding: 8px 16px;
            border-radius: 15px;
            font-size: 0.95rem;
            font-weight: bold;
            color: #333;
            box-shadow: 0 2px 5px rgba(0, 0, 0, 0.1);
        }

        .class-switcher {
            margin-bottom: 20px;
            display: flex;
            gap: 15px;
            justify-content: center;
            align-items: center;
        }

        .class-btn {
            background: linear-gradient(135deg, #a8edea 0%, #fed6e3 100%);
            border: 3px solid transparent;
            padding: 12px 25px;
            font-size: 1.1rem;
            font-weight: bold;
            border-radius: 25px;
            cursor: pointer;
            transition: all 0.3s ease;
            color: #333;
            box-shadow: 0 4px 10px rgba(0, 0, 0, 0.1);
        }

        .class-btn:hover {
            transform: translateY(-2px);
            box-shadow: 0 6px 15px rgba(0, 0, 0, 0.2);
        }

        .class-btn.active {
            background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
            color: white;
            border-color: #667eea;
            transform: scale(1.1);
        }

        .student-count {
            margin-top: 5px;
            font-size: 0.9rem;
            color: #764ba2;
            font-weight: normal;
        }

        .sound-toggle {
            position: fixed;
            bottom: 20px;
            right: 20px;
            background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
            color: white;
            border: none;
            padding: 12px 20px;
            border-radius: 50px;
            cursor: pointer;
            font-size: 1.2rem;
            box-shadow: 0 4px 15px rgba(102, 126, 234, 0.4);
            transition: all 0.3s ease;
            z-index: 1000;
        }

        .sound-toggle:hover {
            transform: translateY(-2px);
            box-shadow: 0 6px 20px rgba(102, 126, 234, 0.6);
        }

        .sound-toggle.muted {
            background: linear-gradient(135deg, #95a5a6 0%, #7f8c8d 100%);
        }

        /* 响应式设计 */
        @media (max-width: 768px) {
            h1 {
                font-size: 1.8rem;
            }

            .subtitle {
                font-size: 1rem;
            }

            #currentName {
                font-size: 4rem;
                min-height: 100px;
            }

            #currentName.winner {
                font-size: 5.5rem;
            }

            #startBtn {
                padding: 18px 40px;
                font-size: 1.4rem;
            }

            .name-display {
                padding: 50px 20px;
            }

            .container {
                padding: 25px 20px;
            }

            .class-btn {
                padding: 10px 20px;
                font-size: 1rem;
            }
        }

        @media (max-width: 480px) {
            h1 {
                font-size: 1.5rem;
            }

            #currentName {
                font-size: 3rem;
                min-height: 80px;
            }

            #currentName.winner {
                font-size: 4rem;
            }

            #startBtn {
                padding: 15px 35px;
                font-size: 1.2rem;
            }

            .class-switcher {
                flex-direction: column;
                gap: 10px;
            }

            .class-btn {
                width: 100%;
            }

            .sound-toggle {
                bottom: 10px;
                right: 10px;
                padding: 10px 15px;
                font-size: 1rem;
            }
        }
    </style>
</head>
<body>
    <!-- 可爱的背景装饰 -->
    <div class="decoration" style="top: 10%; left: 10%;">📚</div>
    <div class="decoration" style="top: 20%; right: 15%;">✏️</div>
    <div class="decoration" style="bottom: 15%; left: 20%;">🎓</div>
    <div class="decoration" style="bottom: 20%; right: 10%;">🌟</div>
    <div class="decoration" style="top: 50%; left: 5%;">🎨</div>
    <div class="decoration" style="top: 60%; right: 8%;">🎪</div>

    <div class="container">
        <h1>🎲 魏女神的课堂点名神器 🎲</h1>
        <p class="subtitle">据说被抽中的同学都能考满分哦~ 😎</p>

        <!-- 班级切换器 -->
        <div class="class-switcher">
            <button class="class-btn active" onclick="switchClass('class1')">📘 高三一班</button>
            <button class="class-btn" onclick="switchClass('class2')">📗 高三二班</button>
        </div>

        <div class="name-display">
            <div id="currentName">准备好了吗？</div>
        </div>

        <div class="controls">
            <button id="startBtn" onclick="toggleRoll()">🚀 开始抽背</button>
        </div>

        <div class="speed-control">
            <div class="speed-label">
                <span>🐢 慢速</span>
                <span>滚动速度调节器</span>
                <span>🚀 光速</span>
            </div>
            <input type="range" id="speedSlider" min="10" max="200" value="50" oninput="updateSpeed()">
            <div class="speed-value">
                当前速度: <span id="speedDisplay">50</span>%
                <span id="speedEmoji">⚡</span>
            </div>
        </div>

        <div class="student-list">
            <div class="student-list-header" onclick="toggleStudentList()">
                <h3>👥 <span id="className">高三一班</span> 花名册</h3>
                <span class="toggle-icon" id="toggleIcon">🔽</span>
            </div>
            <div class="student-count">共 <span id="studentCount">0</span> 人 · 点击展开查看</div>
            <div class="student-chips" id="studentChips">
            </div>
        </div>

        <div class="fun-facts" id="funFact">
            💡 小贴士: 据不完全统计，滑轮拉满时被抽中的概率更加随机哦~
        </div>
    </div>

    <!-- 音频元素 -->
    <audio id="rollingSound" loop>
        <source src="data:audio/wav;base64,UklGRnoGAABXQVZFZm10IBAAAAABAAEAQB8AAEAfAAABAAgAZGF0YQoGAACBhYqFbF1fdJivrJBhNjVgodDbq2EcBj+a2/LDciUFLIHO8tiJNw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enRvbGxsbHR6gYWLkZGLhYF6dG9sa2xsdHqBhYuRkYuFgXp0b2xsbGx0eoGFi5GRi4WBenRvbWxsbHR6gYWLkZGLhYF6dG9sa2xsdHqBhYuRkYuFgXp0b2xsbGx0eoGFi5GRi4WBenRvbGxsbHR6gYWLkZGLhYF6dG9sa2xsdHqBhYuRkYuFgXp0b2xsbGx0eoGFi5GRi4WBenRvbGtsbHR6gYWLkZGLhYF6dG9sa2xsdHqBhYuRkYuFgXp0b2xrbGx0eoGFi5GRi4WBenRvbGxsbHR6gYWLkZGLhYF6dG9sa2xsdHqBhYuRkYuFgXp0b2xsbGx0eoGFi5GRi4WBenRvbGtsbHR6gYWLkZGLhYF6dG9sa2xsdHqBhYuRkYuFgXp0b2xrbGx0eoGFi5GRi4WBenRvbGxsbHR6gYWLkZGLhYF6dG9sa2xsdHqBhYuRkYuFgXp0b2xsbGx0eoGFi5GRi4WBenRvbGtsbHR6gYWLkZGLhYF6dG9sa2xsdHqBhYuRkYuFgXp0b2xrbGx0eoGFi5GRi4WBenRvbGxsbHR6gYWLkZGLhYF6dG9sa2xsdHqBhYuRkYuFgXp0b2xsbGx0eoGFi5GRi4WBenRvbGtsbHR6gYWLkZGLhYF6dG9sa2xsdHqBhYuRkYuFgXp0b2xrbGx0eoGFi5GRi4WBenRvbGxsbHR6gYWLkZGLhYF6dG9sa2xsdHqBhYuRkYuFgXp0b2xsbGx0eoGFi5GRi4WBenRvbGtsbHR6gYWLkZGLhYF6dG9sa2xsdHqBhYuRkYuFgXp0b2xrbGx0eoGFi5GRi4WBenRvbGxsbHR6gYWLkZGLhYF6dG9sa2xsdA==" type="audio/wav">
    </audio>

    <!-- 音效控制按钮 -->
    <button class="sound-toggle" id="soundToggle" onclick="toggleSound()">🔊 音效开</button>

    <script>
        // 班级数据
        const classData = {
            class1: {
                name: '高三一班',
                students: [
                    '陈宇航', '李依婷', '杨琳娜', '陈佳乐', '屈怡斌', '刘佳琪', '赵奥傲', '王平',
                    '刘毅博', '杜盼盼', '屈江维', '彭璇', '周朝阳', '李婉婷', '杨雪莹', '杨佳蓉',
                    '梁邵阳', '周旭乐', '刘佳瑞', '王鑫', '司嘉怡', '陈之航', '韩馨宇', '闫恒',
                    '魏萌', '张增超', '郭宇孝', '吴子恒', '王璇', '李睿', '王奥泽', '张江浩',
                    '强思瑶', '韩晨柯', '葛倩琳', '吴欣阳', '周雪雅', '刘佩', '王思豪', '周同',
                    '高佳欣', '张阳静', '郭朝阳', '郑震柱', '韩怡阳', '赵奥琪', '朱家骥', '李悦',
                    '王家欢', '袁之若', '韩佳歧', '苏宇涛', '董文朋', '张颖', '袁志若', '刘文贤',
                    '韩佳琪', '陈新毅', '董文鹏'
                ]
            },
            class2: {
                name: '高三二班',
                students: [
                    '待添加学生1', '待添加学生2', '待添加学生3'
                ]
            }
        };

        let currentClass = 'class1';
        let students = classData.class1.students;
        let isRolling = false;
        let rollInterval = null;
        let speed = 50; // 默认速度
        let intervalTime = 100; // 默认间隔时间(ms)

        // 音频元素
        const rollingSound = document.getElementById('rollingSound');
        const resultSound = document.getElementById('resultSound');
        
        // 设置音量
        rollingSound.volume = 0.3;
        resultSound.volume = 0.5;

        // 音效开关状态
        let soundEnabled = true;

        const funFacts = [
            '💡 小贴士: 据不完全统计，滑轮拉满时被抽中的概率更加随机哦~',
            '🎯 魏女神说: 背得越好，运气越好！',
            '🌟 温馨提示: 被抽中是一种幸运，是老师对你的信任~',
            '📖 俗话说: 不怕同学是学霸，就怕学霸被抽中！',
            '🎪 据传说: 点名器都是有灵性的，它知道谁准备好了~',
            '🎨 友情提醒: 抽中后请保持微笑，这会给你加分哦！',
            '✨ 秘密: 其实老师已经偷偷看了你的笔记本~'
        ];

        function updateSpeed() {
            speed = document.getElementById('speedSlider').value;
            document.getElementById('speedDisplay').textContent = speed;

            // 更新速度表情
            const emoji = speed < 40 ? '🐢' : speed < 70 ? '⚡' : speed < 120 ? '🚀' : '💫';
            document.getElementById('speedEmoji').textContent = emoji;

            // 计算间隔时间（速度越高，间隔越短）
            // 速度10时间隔200ms，速度200时间隔10ms
            intervalTime = 210 - speed;

            // 如果正在滚动，更新滚动速度
            if (isRolling) {
                clearInterval(rollInterval);
                startRolling();
            }
        }

        function toggleRoll() {
            const btn = document.getElementById('startBtn');
            const nameDisplay = document.getElementById('currentName');

            if (!isRolling) {
                // 开始滚动
                isRolling = true;
                btn.textContent = '⏸️ 暂停抽背';
                btn.classList.add('running');
                nameDisplay.classList.remove('winner');
                startRolling();

                // 播放滚动音效
                if (soundEnabled) {
                    rollingSound.currentTime = 0;
                    rollingSound.play().catch(e => console.log('音频播放失败:', e));
                }

                // 更换趣味提示
                changeFunFact();
            } else {
                // 停止滚动，显示结果
                isRolling = false;
                btn.textContent = '🚀 开始抽背';
                btn.classList.remove('running');
                clearInterval(rollInterval);

                // 停止滚动音效
                rollingSound.pause();
                rollingSound.currentTime = 0;

                // 播放结果音效
                if (soundEnabled) {
                    resultSound.currentTime = 0;
                    resultSound.play().catch(e => console.log('音频播放失败:', e));
                }

                // 放大显示中奖名字
                nameDisplay.classList.add('winner');

                // 庆祝动画
                celebrate();

                // 显示特殊提示
                const winner = nameDisplay.textContent;
                document.getElementById('funFact').textContent =   `🎉 恭喜 ${winner} 同学被幸运之神眷顾！请做好准备~`;
            }
        }

        function startRolling() {
            rollInterval = setInterval(() => {
                const randomIndex = Math.floor(Math.random() * students.length);
                document.getElementById('currentName').textContent = students[randomIndex];
            }, intervalTime);
        }

        function celebrate() {
            // 发射表情雨
            const emojis = ['🎉', '🎊', '⭐', '✨', '🌟', '💫', '🎈', '🎁', '🏆', '👏'];

            for (let i = 0; i < 30; i++) {
                setTimeout(() => {
                    const emoji = document.createElement('div');
                    emoji.className = 'emoji-rain';
                    emoji.textContent = emojis[Math.floor(Math.random() * emojis.length)];
                    emoji.style.left = Math.random() * 100 + '%';
                    emoji.style.top = '-50px';
                    document.body.appendChild(emoji);

                    setTimeout(() => emoji.remove(), 3000);
                }, i * 100);
            }
        }

        function changeFunFact() {
            const randomFact = funFacts[Math.floor(Math.random() * funFacts.length)];
            document.getElementById('funFact').textContent = randomFact;
        }

        // 班级切换函数
        function switchClass(classKey) {
            // 如果正在抽背，先停止
            if (isRolling) {
                toggleRoll();
            }

            // 更新当前班级
            currentClass = classKey;
            students = classData[classKey].students;

            // 更新UI
            const buttons = document.querySelectorAll('.class-btn');
            buttons.forEach((btn, index) => {
                if ((index === 0 && classKey === 'class1') || (index === 1 && classKey === 'class2')) {
                    btn.classList.add('active');
                } else {
                    btn.classList.remove('active');
                }
            });

            // 更新班级名称和花名册
            document.getElementById('className').textContent = classData[classKey].name;
            renderStudentList();

            // 收起花名册
            const chips = document.getElementById('studentChips');
            const icon = document.getElementById('toggleIcon');
            const count = document.getElementById('studentCount');
            chips.classList.remove('show');
            icon.classList.remove('expanded');
            icon.textContent = '🔽';
            count.textContent = `共 ${students.length} 人 · 点击展开查看`;

            // 重置显示
            document.getElementById('currentName').textContent = '准备好了吗？';
            document.getElementById('currentName').classList.remove('winner');
            changeFunFact();
        }

        // 渲染学生花名册
        function renderStudentList() {
            const container = document.getElementById('studentChips');
            container.innerHTML = '';

            students.forEach(student => {
                const chip = document.createElement('span');
                chip.className = 'student-chip';
                chip.textContent = student;
                container.appendChild(chip);
            });

            document.getElementById('studentCount').textContent = students.length;
        }

        // 切换花名册显示/隐藏
        function toggleStudentList() {
            const chips = document.getElementById('studentChips');
            const icon = document.getElementById('toggleIcon');
            const count = document.getElementById('studentCount');
            
            if (chips.classList.contains('show')) {
                chips.classList.remove('show');
                icon.classList.remove('expanded');
                icon.textContent = '🔽';
                count.textContent = `共 ${students.length} 人 · 点击展开查看`;
            } else {
                chips.classList.add('show');
                icon.classList.add('expanded');
                icon.textContent = '🔼';
                count.textContent = `共 ${students.length} 人 · 点击收起`;
            }
        }

        // 切换音效开关
        function toggleSound() {
            soundEnabled = !soundEnabled;
            const btn = document.getElementById('soundToggle');
            
            if (soundEnabled) {
                btn.textContent = '🔊 音效开';
                btn.classList.remove('muted');
            } else {
                btn.textContent = '🔇 音效关';
                btn.classList.add('muted');
                // 如果正在播放，停止所有音效
                rollingSound.pause();
                rollingSound.currentTime = 0;
                resultSound.pause();
                resultSound.currentTime = 0;
            }
        }

        // 初始化
        function init() {
            updateSpeed();
            renderStudentList();
            changeFunFact();
        }

        // 执行初始化
        init();

        // 定期更换趣味提示
        setInterval(() => {
            if (!isRolling) {
                changeFunFact();
            }
        }, 5000);
    </script>
</body>
</html>
